package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

/**
内建变量类型：
bool,string
(u)int, (u)int8, (u)int16, (u)int32, (u)int64, uintptr(指针)
byte, rune(字符，32位)
float32,float64,complex64.complex128
*/

//作用域：包内部变量，没有全局变量
var aa = 3
var ss = "kkk"
var bb = true

var (
	cc = 3
	dd = "dd"
	ee = true
)

func calcTriangle(a, b int) int {
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	return c
}

func variable() {
	var a int
	var s string
	fmt.Printf("%d %q\n", a, s)
}

func variableInitialValue() {
	var a, b int = 3, 4
	var s string = "abc"
	fmt.Println(a, b, s)
}

//推断类型
func variableTypeDeduction() {
	var a, b, c, s = 3, 4, true, "deduction"
	fmt.Println(a, b, c, s)
}

//更简单的写法
func variableShorter() {
	a, b, c, s := 3, 4, true, "deduction"
	fmt.Println(a, b, c, s)
}

func euler() {
	c := 3 + 4i
	fmt.Println(cmplx.Abs(c))

	fmt.Printf("%3f", (cmplx.Exp(1i*math.Pi) + 1))
	fmt.Printf("%3f", cmplx.Pow(math.E, 1i*math.Pi)+1)
	fmt.Println()
}

func triangle() {
	var a, b int = 3, 4
	fmt.Println(calcTriangle(a, b))
}

func enums() {
	const (
		cpp    = 0
		java   = 1
		python = 2
		golang = 3
	)

	const (
		//iota 自增枚举值
		b = 1 << (10 * iota)
		kb
		mb
		gb
		tb
		pb
	)
	fmt.Println(cpp, java, python, golang)
	fmt.Println(b, kb, mb, tb, pb)

}

//常量
func consts() {
	const filename string = "abc.txt"
	const a, b = 3, 4
	var c int
	c = int(math.Sqrt(a*a + b*b))
	fmt.Println(filename, c)
}

func main() {

	fmt.Println("Hello World")

	variable()

	variableInitialValue()

	variableTypeDeduction()

	variableShorter()

	fmt.Println(aa, bb, ee)

	euler()

	triangle()

	consts()

	enums()
}
